package com.googlecode.classgrep.info;

import java.util.ArrayList;
import java.util.List;

import org.objectweb.asm.Type;


public class MethodInfo extends Annotatable implements Info {
	
	
    private final ClassInfo declaringClass;
    private final String name;
    private final List<List<AnnotationInfo>> parameterAnnotations = new ArrayList<List<AnnotationInfo>>();
    private final String desc;
    private Object original;
    private String returnType;
    
    /*public MethodInfo(ClassInfo info, Constructor<?> constructor){
        super(constructor);
        this.declaringClass = info;
        this.name = "<init>";
        this.returnType = Void.TYPE.getName();
        this.original = constructor;
    }

    public MethodInfo(ClassInfo info, Method method){
        super(method);
        this.declaringClass = info;
        this.name = method.getName();
        this.returnType = method.getReturnType().getName();
        this.original = method;
    }*/

    public MethodInfo(ClassInfo declarignClass, String name, String desc) {
        this.declaringClass = declarignClass;
        this.name = name;
        this.desc = desc;
        this.returnType = Type.getReturnType(desc).getDescriptor();
    }

    public List<List<AnnotationInfo>> getParameterAnnotations() {
        return parameterAnnotations;
    }

    public List<AnnotationInfo> getParameterAnnotations(int index) {
        if (index >= parameterAnnotations.size()) {
            for (int i = parameterAnnotations.size(); i <= index; i++) {
                List<AnnotationInfo> annotationInfos = new ArrayList<AnnotationInfo>();
                parameterAnnotations.add(i, annotationInfos);
            }
        }
        return parameterAnnotations.get(index);
    }

    public String getName() {
        return name;
    }

    public ClassInfo getDeclaringClass() {
        return declaringClass;
    }

    public String getReturnType() {
        return returnType;
    }
    
    public String getDesc(){
    	return desc;
    }
    
    public Object getOriginal() {
		return original;
	}

	void setOriginal(Object original) {
		this.original = original;
	}

	@Override
    public String toString() {
        return original.toString();
    }
}